﻿using Core.LockStep;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

[LockstepInfo]
public class BattleInfoData : LockstepInfoData
{
    public int playerCount;
    public List<int> playerIds = new List<int>();

    public override LockstepInfoData ReadFrom(IFrameDataStream stream)
    {
        playerCount = stream.ReadInt32();

        playerIds.Clear();
        for (int i = 0; i < playerCount; i++)
            playerIds.Add(stream.ReadInt32());

        return base.ReadFrom(stream);
    }

    public override void WriteTo(IFrameDataStream stream)
    {
        stream.WriteInt32(playerCount);

        foreach (var item in playerIds)
            stream.WriteInt32(item);

        base.WriteTo(stream);
    }

    public override void Clear()
    {
        playerCount = 0;
        playerIds.Clear();
        base.Clear();
    }

    public override string GetDescription()
    {
        var builder = new StringBuilder();

        builder.AppendLine("=======战斗数据=======");

        builder.AppendLine($"playerId:{playerId}");

        builder.AppendLine($"playerCount:{playerCount}");

        foreach (var item in playerIds)
            builder.Append($"{item},");
        builder.AppendLine();

        builder.AppendLine("=====================");

        return builder.ToString();
    }
}